<html>
<head><meta charset="utf-8"><title>Access to layout info for fn args during metadata creation? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Access.20to.20layout.20info.20for.20fn.20args.20during.20metadata.20creation.3F.html">Access to layout info for fn args during metadata creation?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242791742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Access%20to%20layout%20info%20for%20fn%20args%20during%20metadata%20creation%3F/near/242791742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Richard Cobbe <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Access.20to.20layout.20info.20for.20fn.20args.20during.20metadata.20creation.3F.html#242791742">(Jun 15 2021 at 20:06)</a>:</h4>
<p>I need to access layout information (primarily size and alignment, but see also below) for the parameters to an <code>extern "stdcall"</code> function during metadata creation for a crate.  What's the easiest/best way to access this information?  I'll use this information in methods of the <code>Collector</code> type defined in rustc_metadata/src/native_libs.rs.</p>
<p>I need access to this info  in order to add support for stdcall functions to the work I recently did to implement <code>#[link(kind = "raw-dylib")]</code>.  On 32-bit x86 (Windows only), to add a stdcall function <code>f</code> to the generated import library, I need to synthesize the decorated form of the name, which is something like <code>_f@8</code>, where the number specifies the size of the argument list, in bytes, apparently including any arguments that might be passed in registers.  I know how to get the <code>Ty</code> information for the parameters, but working out the layout from that in all cases is labor-intensive, error-prone, and redundant: we've got this information somewhere in the compiler already.  I'm particularly concerned with cases like <code>Option&lt;&amp;T&gt;</code> and by-value struct arguments; detecting when the nullable pointer optimization applies is logic I'd really prefer not to duplicate.  Is this info readily available?</p>
<p>Thanks!</p>



<a name="242833265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Access%20to%20layout%20info%20for%20fn%20args%20during%20metadata%20creation%3F/near/242833265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Access.20to.20layout.20info.20for.20fn.20args.20during.20metadata.20creation.3F.html#242833265">(Jun 16 2021 at 06:06)</a>:</h4>
<p>tcx.layout_of?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>